/**
    ******************************************************************************
    * @file    handler.h
    * @author  debian
    * @version V1.0.0
    * @date    2020-01-20
    * @brief   hanldler类
    ******************************************************************************
    * @attention
    *
    *
    ******************************************************************************
    */ 

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HANLDLER_H
#define __HANLDLER_H

#ifdef __cplusplus
    extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/


/** @addtogroup DataStruct_Driver
    * @{
    */

/** @addtogroup hanldler
    * @{
    */
class Handler
{
public:
    Handler(Handler *handler) {
        printf("handler 构造函数\n");
        set_next(handler);
    }

    void handle(Resqest* resq) {
        printf("gjgj %d %d %d %d\n", resq->get_loan(), resq->get_type_loan(), max_loan, type_loan);
        if(resq->get_loan() * resq->get_type_loan() < max_loan * type_loan) {
            printf("找到了 max_loan=%d\n", max_loan * type_loan);
        }else if(next_handler != nullptr){
            printf("找下一个 %p\n", next_handler);
            next_handler->handle(resq);
        }else {
            printf("结束了\n");
        }
    }

    void show() {
        printf("Handler %p %d\n", next_handler, max_loan);
    }

    int set_max_loan(unsigned int max_loan) {
        this->max_loan = max_loan;
    }
protected:
    Handler *next_handler;

private:
    unsigned int max_loan = 1;
    unsigned int type_loan = 10000;   //单位是1万
    void set_next(Handler *handler) {
        next_handler = handler;
    }
};

/* Exported types ------------------------------------------------------------*/
/** @defgroup 
    * @{
    */ 



/**
    * @}
    */


/* Exported constants --------------------------------------------------------*/

/* Exported macro ------------------------------------------------------------*/

/* Exported functions --------------------------------------------------------*/ 
/* Initialization and de-initialization functions *******************************/
/** @addtogroup hanldler_Exported_Functions
    * @{
    */

/** @addtogroup hanldler_Exported_Functions_Group1
    * @{
    */

/**
    * @}
    */

/* operation functions *******************************************************/
/** @addtogroup hanldler_Exported_Functions_Group2
    * @{
    */



/**
    * @}
    */

/**
    * @}
    */ 

/**
    * @}
    */

/**
    * @}
    */


#ifdef __cplusplus
}
#endif

#endif /* __HANLDLER_H */

/******************* (C) 2020 HOME 深圳龙华 *****END OF FILE****/

